package com.example;
// 抽象类CaffeineBeverage作为咖啡饮料的模板类
abstract class CaffeineBeverage {
    // 模板方法，定义饮料制作的基本流程
    final void prepareRecipe() {
        boilWater();
        brew();
        pourInCup();
        addCondiments();
        pack();
    }
    // 烧开水
    protected void boilWater() {
        System.out.println("Boiling water");
    }

    // 冲泡
    protected abstract void brew();

    // 倒入杯子
    protected void pourInCup() {
        System.out.println("Pouring into cup");
    }

    // 添加调料，咖啡可以加糖和牛奶，茶可以放柠檬
    protected abstract void addCondiments();

    // 包装
    protected void pack() {
        System.out.println("Packing the beverage");
    }
}

// 咖啡类，继承自CaffeineBeverage
class Coffee extends CaffeineBeverage {
    @Override
    protected void brew() {
        System.out.println("Dripping coffee through filter");
    }

    @Override
    protected void addCondiments() {
        System.out.println("Adding sugar and milk");
    }
}

// 茶类，继承自CaffeineBeverage
class Tea extends CaffeineBeverage {
    @Override
    protected void brew() {
        System.out.println("Steeping the tea");
    }

    @Override
    protected void addCondiments() {
        System.out.println("Adding lemon");
    }
}

